import * as echarts from 'echarts'

function create(name, anaData, type, num){
    const chart = echarts.init(document.querySelector(name));

    let config = {
        rotate: 90,
        align: 'left',
        verticalAlign: 'middle',
        position: 'insideBottom',
        distance: 15,
    };
    const labelOption = {
        show: true,
        position: config.position,
        distance: config.distance,
        align: config.align,
        verticalAlign: config.verticalAlign,
        rotate: config.rotate,
        formatter: '{c}  {name|{a}}',
        fontSize: 12,
        rich: {
            name: {}
        }
    };
    let option = {
        legend: {
            data: [],
            textStyle: {
                color: 'white' // 设置标题文字颜色为红色
            },
        },
        toolbox: {
            show: false,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
                mark: { show: true },
                dataView: { show: true, readOnly: false },
                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                restore: { show: true },
                saveAsImage: { show: true }
            }
        },
        xAxis: [
            {
                type: 'category',
                axisTick: { show: false },
                data: []
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: 'none',
                type: 'bar',
                barGap: 0,
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: []
            },
            {
                name: 'none',
                type: 'bar',
                barGap: 0,
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: []
            },
            {
                name: 'none',
                type: 'bar',
                barGap: 0,
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: []
            }
        ]
    };
    if(type === 0){
        option.series[0].data.push(anaData.diameter[num].x)
        option.series[1].data.push(anaData.diameter[1].y)
        option.series[2].data.push(anaData.diameter[1].z)
        option.series[0].name = '直径:x'
        option.series[1].name = '直径:y'
        option.series[2].name = '直径:z'
        option.legend.data.push('直径:x')
        option.legend.data.push('直径:y')
        option.legend.data.push('直径:z')
        option.xAxis[0].data.push("直径")
    }else{
        option.series[0].data.push(anaData.area[num].xy)
        option.series[1].data.push(anaData.area[num].yz)
        option.series[2].data.push(anaData.area[num].xz)
        option.series[0].name = '面积:xy'
        option.series[1].name = '面积:yz'
        option.series[2].name = '面积:xz'
        option.legend.data.push('面积:xy')
        option.legend.data.push('面积:yz')
        option.legend.data.push('面积:xz')

        option.xAxis[0].data.push("，面积")
    }

    chart.setOption(option)
}

export default {
    create
}